package com.songcha.module_category.ui.decoraction

import android.graphics.Canvas
import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.songcha.library_common.util.dp2px

class CategorySubItemDecoration:RecyclerView.ItemDecoration() {
    override fun getItemOffsets(
        outRect: Rect,
        view: View,
        parent: RecyclerView,
        state: RecyclerView.State
    ) {
        super.getItemOffsets(outRect, view, parent, state)

        val layoutParams: GridLayoutManager.LayoutParams =
            view.layoutParams as GridLayoutManager.LayoutParams

        if(parent.adapter==null) return

        if(layoutParams.spanIndex%2==0){
            outRect.left=22.dp2px()
            outRect.top=8.dp2px()
            outRect.right=16.dp2px()
            outRect.bottom=0.dp2px()
        }else{
            outRect.left=16.dp2px()
            outRect.top=8.dp2px()
            outRect.right=22.dp2px()
            outRect.bottom=0.dp2px()
        }

    }
}